package com.demo.impl;

import com.demo.GreetAboutTime;

import java.util.Calendar;
import java.util.Date;

public class GreetAboutTimeImpl implements GreetAboutTime {
    private int getHour(Date now) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(now);
        return calendar.get(Calendar.HOUR_OF_DAY);
    }

    @Override
    public String greet(Date now) {
        int hour = getHour(now);
        String word;
        if(hour>=6 && hour<12) {
            word = "Good morning!";
        } else if(hour>=12 && hour<19) {
            word = "Good afternoon!";
        } else {
            word = "Good night!";
        }
        return word;
    }
}
